<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.util.logging.Level,java.util.logging.Logger" %>
<%@ page import="java.sql.Statement"%>
<%@page import="java.sql.Connection,java.sql.DriverManager" %>
<%@ page import="java.net.URLDecoder" %>

<%
	//request.setCharacterEncoding("gb2312");
	String id = request.getParameter("id");
	//int id = Integer.parseInt(id_str);
	String trainNum = request.getParameter("trainNum");
	
	String startStation = request.getParameter("startStation");
	if (startStation != null && startStation.length() > 0)
		startStation = URLDecoder.decode(startStation, "UTF-8");
	
	String endStation = request.getParameter("endStation");
	if (endStation != null && endStation.length() > 0)
		endStation = URLDecoder.decode(endStation, "UTF-8");
	
	String StartTime = request.getParameter("StartTime");
	String EndTime = request.getParameter("EndTime");
	
	
	Connection con=null;
	Statement stmt=null;
	ResultSet rs=null;
	String driver="com.mysql.cj.jdbc.Driver";
	String url="jdbc:mysql://localhost:3306/android?serverTimezone=GMT&characterEncoding=utf-8";
	String user="root";
	String passwd="HandQuite229";
    try{
       Class.forName(driver);
       con=DriverManager.getConnection(url, user, passwd);
       if (con == null)
      		System.out.println("con is null");
       }catch(ClassNotFoundException e){
           out.println(e);
       }catch(SQLException e){
    	   out.println(e);
       }
	try{
		stmt=con.createStatement();
		String sql = "select * from traininfo where startStation = '" + startStation + "'&& endStation = '" + endStation + "'";
		System.out.println(sql);
		rs=stmt.executeQuery(sql);
		
		out.println("<book>");
        
		while(rs.next()){
			out.println("<elem>");
			out.println("<id>" + rs.getInt(1) + "</id>");
            out.println("<trainNum>"+rs.getString(2)+"</trainNum>");
            out.println("<startStation>"+rs.getString(3)+"</startStation>");
            out.println("<endStation>"+rs.getString(4)+"</endStation>");
            out.println("<StartTime>"+rs.getString(5)+"</StartTime>");
            out.println("<EndTime>"+rs.getString(6)+"</EndTime>");
            out.println("</elem>");
        }
		
		out.println("</book>");
	}catch (SQLException ex) {
		out.println(ex);
	}
%>
